package com.yin.myproject.hadoop;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.Job;

/**
 * @author Eason
 * @create 2018-03-26 14:25
 **/
public class RemoteMapReduceService {
    public static String startJob() throws Exception {
        Job job = Job.getInstance();
        job.setJobName("xxxx");
        /***************************
         *......
         *在这里，和普通的MapReduce一样，设置各种需要的东西
         *......
         ***************************/
        //下面为了远程提交添加设置：
        Configuration conf = job.getConfiguration();
        conf.set("mapreduce.framework.name", "yarn");
        conf.set("hbase.zookeeper.quorum", "MASTER:2181");
        conf.set("fs.default.name", "hdfs://MASTER:8020");
        conf.set("yarn.resourcemanager.resource-tracker.address", "MASTER:8031");
        conf.set("yarn.resourcemanager.address", "MASTER:8032");
        conf.set("yarn.resourcemanager.scheduler.address", "MASTER:8030");
        conf.set("yarn.resourcemanager.admin.address", "MASTER:8033");
        conf.set("yarn.application.classpath", "$HADOOP_CONF_DIR,"
                +"$HADOOP_COMMON_HOME/*,$HADOOP_COMMON_HOME/lib/*,"
                +"$HADOOP_HDFS_HOME/*,$HADOOP_HDFS_HOME/lib/*,"
                +"$HADOOP_MAPRED_HOME/*,$HADOOP_MAPRED_HOME/lib/*,"
                +"$YARN_HOME/*,$YARN_HOME/lib/*,"
                +"$HBASE_HOME/*,$HBASE_HOME/lib/*,$HBASE_HOME/conf/*");
        conf.set("mapreduce.jobhistory.address", "MASTER:10020");
        conf.set("mapreduce.jobhistory.webapp.address", "MASTER:19888");
        conf.set("mapred.child.java.opts", "-Xmx1024m");

        job.submit();
        //提交以后，可以拿到JobID。根据这个JobID可以打开网页查看执行进度。
        return job.getJobID().toString();
    }

}
